<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script th:src="@{webjars/jquery/3.6.4/jquery.min.js}"></script>
    <link  th:href="@{webjars/bootstrap/5.2.3/css/bootstrap.min.css}" rel="stylesheet">
    <script>
           $(function (){
               $("#all").click(function (){
                    $("[name='del']").prop("checked", $(this).prop("checked"));
               })
               $(".btn-warning").click(function (){
                    var $name = $("[name='del']:checked");
                    if($name.length==0){
                        alert("请选择！");
                    }else{
                        let values="";
                        $("[name='del']:checked").each(function (){
                            values+=$(this).val()+",";
                        })
                        if(confirm("确实要删除"+$("[name='del']:checked").length+"条数据吗？"))
                        $.getJSON(
                            "delete",
                            {ids:values},
                            function (obj){
                                if(obj){
                                    alert("删除成功！")
                                    location='list'
                                }
                            }
                        )
                    }
               })//
               //修改的回显请求
               $(".btn-primary").click(function (){
                   let id=$(this).val();
                   //alert(id);
                   location='find?id='+id;
               })
           })
    </script>
</head>
<body>
     <div class="container">
          <form>
              <input type="text" placeholder="请输入要搜索的姓名" name="mohu" th:value="${mohu}">
              <button class="btn btn-success">搜索</button>
          </form>
              <br><hr>
              <table class="table table-bordered table-hover">
                   <tr>
                       <td>
                           <input type="checkbox" id="all">
                           <button class="btn btn-warning">删除</button>
                       </td>
                       <td>编号</td>
                       <td>姓名</td>
                       <td>性别</td>
                       <td>生日</td>
                       <td>班级</td>
                       <td>
                           <button class="btn btn-info" onclick="location='toadd'">新增</button>
                       </td>
                   </tr>
                  <tr th:each="stu:${pager.list}" th:object="${stu}">
                      <td>
                          <input type="checkbox" name="del" th:value="*{id}">
                      </td>
                      <td th:text="*{id}"></td>
                      <td th:text="*{name}"></td>
                      <td th:text="*{sex}==0 ? '男': '女'"></td>
                      <td th:text="*{#dates.format(birthday,'yyyy年MM月dd日')}"></td>
<!--                      <td th:text="${stu.room.rname}"></td>-->
                      <td th:text="*{room.rname}"></td>
                      <td>
                          <button class="btn btn-primary" th:value="*{id}">修改</button>
                      </td>
                  </tr>
                  <tr>
                      <td colspan="10" align="center">
                          共<span th:text="${pager.total}"></span>条数据，
                          共<span th:text="${pager.pages}"></span>页，当前第<span th:text="${pager.pageNum}"></span>页。
                          <a th:href="@{list(offset=1,mohu=${mohu})}">首页</a>
                          <a th:if="${pager.hasPreviousPage}" th:href="@{list(offset=${pager.pageNum}-1,mohu=${mohu})}">上页</a>
                          <a th:if="${pager.hasNextPage}" th:href="@{list(offset=${pager.pageNum}+1,mohu=${mohu})}">下页</a>
                          <a th:href="@{list(offset=${pager.pages},mohu=${mohu})}">末页</a>
                      </td>
                  </tr>
              </table>

     </div>
</body>
</html>
